% Test the function applyH filter.
%
% Yoel Shkolnisky, December 2010.

explim=12;
for precond=0:1
	for n=2.^(1:explim)
		precision='double';
		if n > 2^(explim-1)
			precision='single';
		end
        A=rand(n,n);
        tic;
        [pp1 pp2]=optimizedPPFT2D(A,precision);
        if precond
            B=preconditionedAdjointPPFT2D(pp1,pp2,precision);
        else
            B=optimizedAdjointPPFT2D(pp1,pp2,precision);
        end
        t1 = toc;
        L=3*n-2; %n+2n-1-1
        filename=sprintf('filters%sH2Dfilter%dprecond%dprecision%s.dat',filesep,n,precond,precision);
        if exist(filename,'file')
            H=load2DHFilter(filename,precision);
        else
            H=save2DHFilter(filename,n,precond,precision);
        end

        Hhat=fftn(H.filter,[L L]);

        tic;      
        Cc=applyHFilter2D(A,Hhat);
        t2=toc;

        reportTestResult(n,(norm(B(:)-Cc(:))./norm(B(:))),t1/t2,precision);    
    end
end
